package cate.game.gm.sub;

import cate.game.GameBody;
import cate.game.role.Role;
import cp.solution.business.gm.GmBanEntity;
import easy.java.practice.errorcode.EcResult;
import org.apache.commons.lang3.StringUtils;

public class GmBanRun {

    public static EcResult run(GameBody game, GmBanEntity cmd) {
        EcResult r = new EcResult();
        if(StringUtils.isBlank(cmd.getType())) {
            return r.fail("type不能为空");
        }
        Role role = game.role.getRole(cmd.getRoleId());
        switch (cmd.getType()) {
            case GmBanEntity.TYPE_CHAT:
                role.getChat().handleForbid(cmd.getUntil(), cmd.getReason());
                break;
            case GmBanEntity.TYPE_LOGIN:
                role.getBase().login.ban(cmd.getUntil(), cmd.getReason());
                role.save();
                role.getCc().kickOff(role.getGame());
                break;
            default:
                return r.fail("不支持的type");
        }
        return r.success();
    }
}
